
package net.atremmedia.gwt.actionjava.examples.basics.samples;

import net.atremmedia.gwt.actionjava.examples.AJExample;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.display.Sprite;
import actionjava.events.mouse.MouseEvent;
import actionjava.events.mouse.MouseEvent.MouseEventType;
import actionjava.events.mouse.StageMoveHandler;
import actionjava.events.tick.TickEvent;
import actionjava.geom.Color;

public class DrawingCurves extends AJExample
{
	public static final String NAME = "Drawing curves";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-basics/src/main/java/net/atremmedia/gwt/actionjava/examples/basics/samples/DrawingCurves.java";

	private Sprite curveSprite;
	private Graphics curveGraphs;

	private double x0 = 100;
	private double y0 = 200;
	private double x1 = 0;
	private double y1 = 0;
	private double x2 = 300;
	private double y2 = 200;

	public DrawingCurves(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	@Override
	public void run()
	{
		curveSprite = new Sprite();
		curveGraphs = curveSprite.getGraphics();
		addChild(curveSprite);

		addEventListener(MouseEventType.STAGE_MOUSE_MOVE, new StageMoveHandler()
		{
			@Override
			protected void stageMoveHandler(MouseEvent event)
			{
				x1 = event.getRawX();
				y1 = event.getRawY();
			}
		});
	}

	@Override
	public void onRenderTick(TickEvent event)
	{
		curveGraphs.clear();
		curveGraphs.beginStroke(Color.BLACK.getHexValue());
		curveGraphs.setStrokeStyle(1);
		curveGraphs.moveTo(x0, y0);
		curveGraphs.curveTo(x1, y1, x2, y2);
	}
}
